﻿@inherits LayoutComponentBase
@inject SwalService swalService
@inject NavigationManager navigationManager

<Layout SideWidth="0" IsPage="true" ShowGotoTop="true" ShowCollapseBar="true"
        IsFullSide="@IsFullSide" IsFixedHeader="@IsFixedHeader" IsFixedFooter="@IsFixedFooter" ShowFooter="@ShowFooter"
        TabDefaultUrl="/"
        Menus="@Menus"  UseTabSet="@UseTabSet" AdditionalAssemblies="new[] { GetType().Assembly }" class="@Theme">
    <Header>
        <span class="ms-3 flex-sm-fill d-none d-sm-block">Kite Gateway</span>
        <div class="flex-fill d-sm-none">
        </div>
        <Logout ImageUrl="images/kitelogo.png" DisplayName="@(Administrator.NickName)" UserName="@(Administrator.AdminName)">
            <LinkTemplate>
                <LogoutLink Url="/Logout" />
            </LinkTemplate>
        </Logout>
    </Header>
    <Side>
        <div class="layout-banner">
            <div class="layout-title">
                <span>后台管理</span>
            </div>
        </div>
    </Side>
    <Main>
        <CascadingValue Value="this" IsFixed="true">
            @Body
        </CascadingValue>
    </Main>
    <Footer>
        <div class="text-center flex-fill">
            
        </div>
    </Footer>
    <NotFound>
        <p>Sorry, there's nothing at this address.</p>
    </NotFound>
</Layout>
@code {
    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        if (Administrator.Id == Guid.Empty)
        {

            var op = new SwalOption()
                {
                    Category = SwalCategory.Warning,
                    Title = "你还未登录,请先登录",
                    ShowClose = false
                };
            op.ButtonTemplate = new RenderFragment(builder =>
            {
                builder.OpenComponent<Button>(0);
                builder.AddAttribute(1, nameof(Button.Text), "前往登录");
                builder.AddAttribute(2, nameof(Button.OnClick), EventCallback.Factory.Create<MouseEventArgs>(this, () =>
                {
                    navigationManager.NavigateTo("/Login");
                    op.Close();
                }));
                builder.CloseComponent();
            });
            await swalService.Show(op);
        }
        await base.OnAfterRenderAsync(firstRender);
	}
 
}